package org.pp.controller;



import org.pp.mapper.UserMapper;
import org.pp.entity.User;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
public class TestController {

    @Autowired
    UserMapper userMapper;
    @GetMapping("/test")
    public String test(){
        List<User> all = userMapper.selectList(null);
        if(!all.isEmpty()){
            System.out.println(all.get(0));
        }
        return "OK,test";
    }

    @GetMapping("/add")
    public String add(){
        User user= new User();
        user.setName("小名");
        user.setPwd("123456");
        //userMapper.insert(user);
        userMapper.add(user);
        return "OK,test";
    }


    @GetMapping("/delete")
    public String delete() {
        //int i = userMapper.deleteById(1);
        int i = userMapper.deleteByUserId(1);
        System.out.printf("删除了%s条%n", i);
        return "OK,test";
    }

    @GetMapping("/update")
    public String update() {
        User user = new User();
        user.setName("小明update");
        user.setPwd("123456");
        user.setId(1);//update ... where id=xxx
        userMapper.updateByUserId(user);
        //userMapper.updateById(user);
        return "OK,test";
    }

    @GetMapping("/get")
    public String get(){
        //User user = userMapper.selectById(2);
        User user = userMapper.get(2,"小明");
        System.out.println(user);
        return "OK,test";
    }


}
